﻿using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

[RequireComponent(typeof(ParticleSystem))]
public class SpawnOnParticleCollision : MonoBehaviour
{
    [CompilerGenerated]
    private static Action<ParticleCollisionEvent> <>f__am$cache5;
    private List<ParticleCollisionEvent> evts;
    public Action<ParticleCollisionEvent> onParticleCollision;
    public Transform prefab;
    private ParticleSystem ps;
    public bool setParentToTarget;

    public SpawnOnParticleCollision()
    {
        if (<>f__am$cache5 == null)
        {
            <>f__am$cache5 = new Action<ParticleCollisionEvent>(SpawnOnParticleCollision.<onParticleCollision>m__155);
        }
        this.onParticleCollision = <>f__am$cache5;
        this.evts = new List<ParticleCollisionEvent>();
    }

    [CompilerGenerated]
    private static void <onParticleCollision>m__155(ParticleCollisionEvent c)
    {
    }

    private void Awake()
    {
        this.ps = base.GetComponent<ParticleSystem>();
    }

    private void OnParticleCollision(GameObject other)
    {
        int num = this.ps.GetCollisionEvents(other, this.evts);
        for (int i = 0; i < num; i++)
        {
            ParticleCollisionEvent event2 = this.evts[i];
            ParticleCollisionEvent event3 = this.evts[i];
            Transform transform = this.prefab.Spawn<Transform>(event2.intersection, Quaternion.LookRotation(event3.velocity));
            if (this.setParentToTarget)
            {
                ParticleCollisionEvent event4 = this.evts[i];
                transform.parent = event4.colliderComponent.transform;
            }
        }
    }
}

